/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nbf', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model MultiComplexRequest {
  arg0?: string(name='arg0'),
  arg1?: int32(name='arg1'),
  arg2?: {
    booleanValue?: boolean(name='booleanValue'),
    intValue?: int32(name='intValue'),
    integerValue?: int32(name='integerValue'),
    longValue?: long(name='longValue'),
    secondInput?: {
      secondInt?: int32(name='secondInt'),
      secondString?: string(name='secondString'),
      thirdList?: [ 
        {
          thirdInt?: int32(name='thirdInt'),
          thirdString?: readable(name='thirdString'),
        }
      ](name='thirdList'),
    }(name='secondInput'),
    stringValue?: string(name='stringValue'),
  }(name='arg2'),
}

model MultiComplexShrinkRequest {
  arg0?: string(name='arg0'),
  arg1?: int32(name='arg1'),
  arg2Shrink?: string(name='arg2'),
}

model MultiComplexResponseBody = {
  booleanValue?: boolean(name='booleanValue'),
  intValue?: int32(name='intValue'),
  integerValue?: int32(name='integerValue'),
  longValue?: long(name='longValue'),
  secondOutput?: {
    secondInt?: int32(name='secondInt'),
    secondString?: string(name='secondString'),
    thirdList?: [ 
      {
        thirdInt?: int32(name='thirdInt'),
        thirdString?: string(name='thirdString'),
      }
    ](name='thirdList'),
  }(name='secondOutput'),
  stringValue?: string(name='stringValue'),
}

model MultiComplexResponse = {
  headers: map[string]string(name='headers'),
  body: MultiComplexResponseBody(name='body'),
}

async function multiComplex(request: MultiComplexRequest): MultiComplexResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return multiComplexWithOptions(request, headers, runtime);
}

async function multiComplexWithOptions(tmpReq: MultiComplexRequest, headers: map[string]string, runtime: Util.RuntimeOptions): MultiComplexResponse {
  Util.validateModel(tmpReq);
  var request = new MultiComplexShrinkRequest{};
  OpenApiUtil.convert(tmpReq, request);
  if (!Util.isUnset(tmpReq.arg2)) {
    request.arg2Shrink = OpenApiUtil.arrayToStringWithSpecifiedStyle(tmpReq.arg2, 'arg2', 'json');
  }
  var query : map[string]any= {};
  if (!Util.isUnset(request.arg0)) {
    query['arg0'] = request.arg0;
  }
  if (!Util.isUnset(request.arg1)) {
    query['arg1'] = request.arg1;
  }
  if (!Util.isUnset(request.arg2Shrink)) {
    query['arg2'] = request.arg2Shrink;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'MultiComplex',
    version = '2021-09-07_14-13-48-762',
    protocol = 'HTTPS',
    pathname = `/kxNineSevenSix/multiComplex`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model SupplierConfirmRequest {
  gatewayUid?: long(name='gatewayUid'),
  items?: [ 
    {
      confirmQuantity?: float(name='confirmQuantity'),
      orderLineId?: long(name='orderLineId'),
      planQuantity?: float(name='planQuantity'),
      productId?: long(name='productId'),
    }
  ](name='items'),
  purchaseOrderNo?: string(name='purchaseOrderNo'),
}

model SupplierConfirmResponseBody = {
  errorCode?: string(name='errorCode'),
  errorMsg?: string(name='errorMsg'),
  result?: string(name='result'),
  success?: boolean(name='success'),
}

model SupplierConfirmResponse = {
  headers: map[string]string(name='headers'),
  body: SupplierConfirmResponseBody(name='body'),
}

async function supplierConfirm(request: SupplierConfirmRequest): SupplierConfirmResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return supplierConfirmWithOptions(request, headers, runtime);
}

async function supplierConfirmWithOptions(request: SupplierConfirmRequest, headers: map[string]string, runtime: Util.RuntimeOptions): SupplierConfirmResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.gatewayUid)) {
    body['gatewayUid'] = request.gatewayUid;
  }
  if (!Util.isUnset(request.items)) {
    body['items'] = request.items;
  }
  if (!Util.isUnset(request.purchaseOrderNo)) {
    body['purchaseOrderNo'] = request.purchaseOrderNo;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'SupplierConfirm',
    version = '2021-09-07_14-13-48-762',
    protocol = 'HTTPS',
    pathname = `/CaiheRoaProduct/6_0_0/SupplierConfirm`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

model YxTestApiRequest {
  gatewayUid?: long(name='gatewayUid'),
  items?: [ 
    {
      confirmQuantity?: float(name='confirmQuantity'),
      orderLineId?: long(name='orderLineId'),
      planQuantity?: float(name='planQuantity'),
      productId?: long(name='productId'),
    }
  ](name='items'),
  purchaseOrderNo?: string(name='purchaseOrderNo'),
}

model YxTestApiResponseBody = {
  errorCode?: string(name='errorCode'),
  errorMsg?: string(name='errorMsg'),
  result?: string(name='result'),
  success?: boolean(name='success'),
}

model YxTestApiResponse = {
  headers: map[string]string(name='headers'),
  body: YxTestApiResponseBody(name='body'),
}

async function yxTestApi(request: YxTestApiRequest): YxTestApiResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return yxTestApiWithOptions(request, headers, runtime);
}

async function yxTestApiWithOptions(request: YxTestApiRequest, headers: map[string]string, runtime: Util.RuntimeOptions): YxTestApiResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.gatewayUid)) {
    body['gatewayUid'] = request.gatewayUid;
  }
  if (!Util.isUnset(request.items)) {
    body['items'] = request.items;
  }
  if (!Util.isUnset(request.purchaseOrderNo)) {
    body['purchaseOrderNo'] = request.purchaseOrderNo;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'YxTestApi',
    version = '2021-09-07_14-13-48-762',
    protocol = 'HTTPS',
    pathname = `/CaiheRoaProduct/6_0_0`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

